<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>交流列表</title>
    <!-- head 中 -->
    <link href="${ctxStatic}/plugin/jquery-weui/lib/weui.min.css" type="text/css" rel="stylesheet"/>
    <link href="${ctxStatic}/plugin/jquery-weui/css/jquery-weui.css" type="text/css" rel="stylesheet"/>
    <style>
        .top_bar {
            height: 7vh;
            line-height: 7vh;
            position: relative;
            background: #3399fe;
        }
        .top_bar a.back_history {
            position: absolute;
            left: 10px;
            top: 8px;
            height: 30px;
        }
        .top_bar h2 {
            color: #fff;
            font-size: 18px;
            font-weight:400;
            /*margin-left: 10px;*/
            text-align: center;
        }
        .top_bar a.finish {
            position: absolute;
            right: 10px;
            top: 1px;
            color: #fff;
        }
        .weui-cell{
            font-size: 16px;
        }
    </style>

</head>

<body ontouchstart ng-app="config" ng-controller="configCtrl" ng-init="init()">
<div class="top_bar txt_center f18">
    <a href="${ctx}/sale/saleTask/form?id={{getId}}" class="back_history"><img src="${ctxStatic}/common/images/back.png"/></a>
    <h2>沟通记录</h2>
    <a href="javascript:void(0);" class="finish" ng-click="addRecord()">添加记录</a>
</div>
<%--添加合作伙伴--%>
<div id="addRecord" class='myfont weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <article class="weui-article" style="margin-top: 5px;">
            <%--<h1>大标题</h1>--%>
            <form id="recordForm">
                <div class="weui-cells weui-cells_form">
                    <%--<div class="weui-cells__title">新增记录</div>--%>
                    <h1 style="text-align: center;margin-top: 5px;margin-bottom: 5px;">新增记录</h1>
                    <div class="weui-cell" style="margin-top: 0px;">
                        <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="recordName">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">工作类型</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="workType">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">客户联系人</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="contacts">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">沟通事由</label></div>
                    </div>
                    <div class="weui-cells weui-cells_form" style="margin-top: 0px;">
                        <div class="weui-cell">
                            <div class="weui-cell__bd">
                                <textarea class="weui-textarea" rows="3" name="reason"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">沟通结果</label></div>
                    </div>
                    <div class="weui-cells weui-cells_form" style="margin-top: 0px;">
                        <div class="weui-cell">
                            <div class="weui-cell__bd">
                                <textarea class="weui-textarea" rows="3" name="result"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">开始时间</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input"  type="text" name="startTime" id="time-start">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">结束时间</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input"  type="text" name="endTime" id="time-end">
                        </div>
                    </div>

                </div>
            </form>
        </article>
        <div class="button_sp_area" style="text-align: center;margin-top: -25px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" ng-click="saveRecord()" >保存</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup">取消</a>
        </div>
    </div>
</div>

<div class="weui-form-preview" ng-repeat="x in saleRecordList">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">{{x.recordName}}</label>
        </div>
    </div>
    <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">内容</label>
            <span class="weui-form-preview__value">{{x.reason}}</span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">结果</label>
            <span class="weui-form-preview__value">{{x.result}}</span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">客户联系人</label>
            <span class="weui-form-preview__value">{{x.contacts}}</span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">工作类型</label>
            <span class="weui-form-preview__value">{{x.workType}}</span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">时间</label>
            <span class="weui-form-preview__value">{{x.startTime | date:"yyyy-MM-dd HH:mm"}} ~ {{x.endTime | date:"yyyy-MM-dd HH:mm"}}</span>
        </div>
    </div>
</div>
<script src="${ctxStatic}/plugin/jquery/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/angular/angular.js"></script>
<scrip src="${ctxStatic}/plugin/jquery-validation/1.14.0/jquery.validate.js"></scrip>
<script src="${ctxStatic}/plugin/jquery-weui/lib/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/js/jquery-weui.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/fastclick.js"></script>
<script src="https://cdn.bootcss.com/jquery-json/2.6.0/jquery.json.min.js"></script>
<script>
    var app = angular.module('config', []);
    app.controller('configCtrl',function($scope) {
        $scope.init = function(){
            $scope.getId = GetQueryString("id");
            $scope.getDataList();
        };


        $scope.getDataList = function(){
            $.ajax({
                url:"${ctx}/sale/saleTask/weChatForm",
                data:{"id":$scope.getId},
                async:false,
                type:"POST",
                success:function(response){
                    $scope.saleTask=response.body.saleTask;
                    if($scope.saleTask!=null){
                        $scope.saleRecordList = $scope.saleTask.saleRecordList;
                        console.log($scope.saleRecordList);
                    }
                }
            });
        };

        $scope.addRecord = function(){
            $.openPopup("#addRecord");
        };

        $scope.saveRecord = function(){
            //获取数据
            var params = {};
            var saleRecordList = [];
            var saleRecord = queryInfos("recordForm");
            saleRecordList.push(saleRecord);
            params.id = $scope.getId;
            params.saleRecordList = saleRecordList;

            //params.saleTask = saleTask;
            $.ajax({
                url:"${ctx}/sale/saleTask/saveRecord",
                async:false,
                type:"POST",
                traditional:true,
                dataType:"JSON",
                contentType:"application/json",
                data:$.toJSON(params),
                success:function(response){
                   if(response.success){
                        $scope.init();
                        $.closePopup("#addRecord");
                    }else{
                        $.toast(response.msg,"text");
                    }
                }
            });
        };


        //时间控件
        $("#time-start").datetimePicker({
            title: '选择时间',
            yearSplit: '-',
            monthSplit: '-',
            dateSplit: ' ',
            times: function () {
                return [  // 自定义的时间
                    {
                        values: (function () {
                            var hours = [];
                            for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                            return hours;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    }/*,
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ''
                    }*/
                ];
            },
            onChange: function (picker, values, displayValues) {
                console.log(values);
            }
        });
        $("#time-end").datetimePicker({
            title: '选择时间',
            yearSplit: '-',
            monthSplit: '-',
            dateSplit: ' ',
            times: function () {
                return [  // 自定义的时间
                    {
                        values: (function () {
                            var hours = [];
                            for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                            return hours;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    }/*,
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ''
                    }*/
                ];
            },
            onChange: function (picker, values, displayValues) {
                console.log(values);
            }
        });



        //获取url参数
        var GetQueryString = function (name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        };

        var queryInfos = function (formId) {
            var d = {};
            var t = $('#'+formId).serializeArray();
            $.each(t, function() {
                if(this.value!=""&&this.value!=null&this.value!=undefined){
                    if(this.value.indexOf("number:")>=0){
                        d[this.name] = this.value.split("number:")[1];
                    }else {
                        d[this.name] = this.value;
                    }
                }
            });
            return d;
        }
    });

    $(function() {
        FastClick.attach(document.body);
    });
</script>
</body>
</html>
